<template>
    <div>

        <card>

            <!-- 主管评级 -->
            <card style="background: #ffffff;height:120px;" dis-hover>
                <p slot="title" >用户主观评级</p>
                <Rate allow-half show-text v-model="assessLevel" @on-change="userLevelChange">
                    <span>{{assessLevel}}分/总分5分</span>
                </Rate>
            </card>

            <!-- 用户标签 -->
            <card style="background: #ffffff;height:300px;margin-top: 3px;position:relative;" dis-hover>
                <p slot="title" >用户标签</p>

                <Select size="small" style="width:310px;margin-bottom: 20px;" @on-change="userTagChange">
                    <Option v-for="item in assessTags" :value="item.id" :key="item.id">
                        <p :style="{'color':item.utColor}">{{ item.utContent }}</p>
                    </Option>
                </Select>

                <div >
                    <Tag closable :color="item.utColor" :name="item.id" v-for="item in assessUTags" @on-close="userTagDelete">{{item.utContent}}</Tag>
                </div>


                <!--低部的添加标签功能-->
                <template>
                    <ColorPicker size="small" recommend v-model="judgeColor" style="position:absolute;bottom: 10px;left: 15px;"/>
                    <Input search enter-button="添加标签" placeholder="最多10个字符" v-model="judgeContent" size="small" @on-search="userTagAdd" style="position:absolute;margin-top: 263px;width: 250px;margin-left: 60px" />
                </template>
            </card>

            <!--历史遗留-->
            <card style="background: #ffffff;height:348px;margin-top: 5px;" dis-hover>
                <p slot="title" >好友信息</p>

                <div class="tpbox" style="margin-top: -10px">
                    <iframe :src="base_url" scrolling="yes" frameborder="0" height="280px" width="320"></iframe>
                </div>

            </card>

            <!--备注-->
            <card style="background: #ffffff;height:415px;margin-top: 3px" dis-hover >
                <p slot="title" >备注</p>
                <Input class="pis-input-none" type="textarea" :rows="4" v-model="markContent" placeholder="请输入备注内容......" style="margin-top: 5px;margin-left: -5px;margin-right: -5px;"/>

                <!--备注提交按钮-->
                <Button type="success" style="position: absolute;right: 30px;top: 130px" size="small" @click="userMarkAdd">提交</Button>

                <!--其他用户输入的备注信息-->
                <Scroll height="220" style="position: absolute;left:10px;right:10px;top: 180px;">
                    <card dis-hover v-for="item in assessMarks" style="margin-bottom: 3px">
                        <!--<h6 slot="title" >{{item.umCreateTime}}</h6>-->

                        <div style="font-size: 8px">{{item.umCreateTime}}</div>
                        <div style="font-size: 12px">{{item.umContent}}</div>
                    </card>

                </Scroll>

            </card>
        </card>
    </div>
</template>
<script>
    export default {
        props: {},
        data() {
            return {

                sendCount:'',
                judgeColor:'#19bd68',
                judgeContent:'',
                markContent:'',

                //用户评级
                assessData:[],
                assessLevel:'0',
                assessTags:[],
                assessUTags:[],
                assessMarks:[],

                pis_u_id:'',
                pis_w_name:'',
                pis_c_name:'',
                pis_md5:'',

                base_url:'',

            };
        },
        computed: {},
        methods: {

            //加载Chat有关信息
            getWxUserAssessAll(){
                let _this = this;

                _this.postRequest('/searchWxUserAssess', {
                    wxUserName:_this.pis_w_name,
                    wxCUserName:_this.pis_c_name,
                    wxMd5:_this.pis_md5,
                }).then(resp=> {
                    if (resp && resp.status == 200) {
                        _this.assessData = JSON.parse(resp.data.obj);

                        //设置用户等级
                        _this.assessLevel = _this.assessData.uaLevel;
                        //设置所有可选Tag
                        _this.assessTags = _this.assessData.pisUserTagsAll;
                        //设置用户选中的Tag
                        _this.assessUTags = _this.assessData.pisUserTags;
                        //其他用户备足
                        _this.assessMarks = _this.assessData.pisUserMarks;

                        //嵌入框架URL
                        _this.base_url = _this.assessData.baseUrl;
                    }
                });
            },

            //用户级别
            userLevelChange(){
                let _this = this;

                _this.postRequest('/addWxUserLevel', {
                    uId:_this.pis_u_id,
                    wxUserName:_this.pis_w_name,
                    wxLevel:this.assessLevel,
                }).then(resp=> {
                    if (resp && resp.status == 200) {

                    }
                });
            },

            //用户标签
            userTagChange(value){
                let _this = this;

                _this.postRequest('/chooseWxUserTag', {
                    uId:_this.pis_u_id,
                    wxUserName:_this.pis_w_name,
                    wxTagId:value,
                }).then(resp=> {
                    if (resp && resp.status == 200) {
                        //console.log("成功",success)
                        _this.assessData = JSON.parse(resp.data.obj);

                        //设置用户等级
                        _this.assessLevel = _this.assessData.uaLevel;
                        //设置所有可选Tag
                        _this.assessTags = _this.assessData.pisUserTagsAll;
                        //设置用户选中的Tag
                        _this.assessUTags = _this.assessData.pisUserTags;
                        //其他用户备足
                        _this.assessMarks = _this.assessData.pisUserMarks;
                    }
                });
            },

            //删除标签
            userTagDelete(value,name){
                let _this = this;

                _this.postRequest('/deleteWxUserTag', {
                    uId:_this.pis_u_id,
                    wxUserName:_this.pis_w_name,
                    wxTagId:name,
                }).then(resp=> {
                    if (resp && resp.status == 200) {
                        _this.assessData = JSON.parse(resp.data.obj);

                        //设置用户等级
                        _this.assessLevel = _this.assessData.uaLevel;
                        //设置所有可选Tag
                        _this.assessTags = _this.assessData.pisUserTagsAll;
                        //设置用户选中的Tag
                        _this.assessUTags = _this.assessData.pisUserTags;
                        //其他用户备足
                        _this.assessMarks = _this.assessData.pisUserMarks;
                    }
                });
            },

            //新增用户标签
            userTagAdd(value,name){
                let _this = this;

                _this.postRequest('/addWxUserTag', {
                    uId:_this.pis_u_id,
                    wxUserName:_this.pis_w_name,
                    color:_this.judgeColor,
                    content:_this.judgeContent,
                }).then(resp=> {
                    if (resp && resp.status == 200) {
                        _this.assessData = JSON.parse(resp.data.obj);

                        //设置用户等级
                        _this.assessLevel = _this.assessData.uaLevel;
                        //设置所有可选Tag
                        _this.assessTags = _this.assessData.pisUserTagsAll;
                        //设置用户选中的Tag
                        _this.assessUTags = _this.assessData.pisUserTags;
                        //其他用户备足
                        _this.assessMarks = _this.assessData.pisUserMarks;

                        _this.judgeContent = '';
                    }
                });
            },

            //新增用户备注
            userMarkAdd(){
                if(this.markContent !== ''){
                    let _this = this;
                    _this.postRequest('/addWxUserMark', {
                        uId:_this.pis_u_id,
                        wxUserName:_this.pis_w_name,
                        color:'',
                        content:_this.markContent,
                    }).then(resp=> {
                        if (resp && resp.status == 200) {
                            _this.assessData = JSON.parse(resp.data.obj);

                            //设置用户等级
                            _this.assessLevel = _this.assessData.uaLevel;
                            //设置所有可选Tag
                            _this.assessTags = _this.assessData.pisUserTagsAll;
                            //设置用户选中的Tag
                            _this.assessUTags = _this.assessData.pisUserTags;
                            //其他用户备足
                            _this.assessMarks = _this.assessData.pisUserMarks;

                            _this.markContent = '';
                        }
                    });
                }
            },

        },
        created(){

            //获取参数
            this.pis_u_id = this.$route.query.uid;
            this.pis_w_name = this.$route.query.wname;
            this.pis_c_name = this.$route.query.cname;
            this.pis_md5 = this.$route.query.md5;

           //查询用户的评级信息
           this.getWxUserAssessAll();
        },
    };
</script>
